package com.linkai.多线程._04_Lamda;

/**
 * @Description: Lamda 表达式
 *               一步一步进行简化，最终到 Lambda 表达式
 * @Author: 林凯
 * @Date: 2021/10/19 19:09
 */
public class TestLamda {

    // 3. 静态内部类
    static class Like2 implements ILike {
        @Override
        public void lambda() {
            System.out.println("i like lambda2");
        }
    }

    public static void main(String[] args) {
        // 接口指向子类
        ILike like = new Like();
        like.lambda();

        like = new Like2();
        like.lambda();

        // 4. 局部内部类
        class Like3 implements ILike {
            @Override
            public void lambda() {
                System.out.println("i like lambda3");
            }
        }

        like = new Like3();
        like.lambda();

        // 5. 匿名内部类; 没有类的名称，必须借助接口或者父类
        like = new ILike() {
            @Override
            public void lambda() {
                System.out.println("i like lambda4");
            }
        };
        like.lambda();

        // 6. 用 lambda 简化
        like = ()->{
            System.out.println("i like lambda5");
        };
        like.lambda();

    }
}

// 2. 实现类
class Like implements ILike {

    @Override
    public void lambda() {
        System.out.println("i like lambda");
    }
}
